﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace BeatingMole
{    
    class CBusMouseMove
    {
        #region "Variable"
        ContentManager _Content;
        #endregion

        #region "CInfo"
        CInfoMouseMove InfoMouseMove;
        #endregion

        #region "Properties"

        #endregion

        #region "Constructor"
        public CBusMouseMove(ContentManager content)
        {
            _Content = content;
            InfoMouseMove = new CInfoMouseMove(_Content);
        }
        #endregion

        #region "Method"
        public void UpdateMouse(GameTime gameTime)
        {
            InfoMouseMove.VecMouse = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            //InfoMouseMove.Delay += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            //if (InfoMouseMove.Delay > 75)
            //{
            InfoMouseMove.Delay = 0;
            InfoMouseMove.IndexPosImages++;
            if (InfoMouseMove.IndexPosImages > InfoMouseMove.PosImages)
                InfoMouseMove.IndexPosImages = 0;
            //}

        }

        public bool AttachEnemy(CInfoEnemy Target)
        {
            if (CGlobalVariable.mouseStateCurrent.LeftButton == ButtonState.Pressed)
            {
                Target.RecEnemy = new Rectangle((int)Target.PosMouse.X,
                    (int)Target.PosMouse.Y,
                    Target.XmlEnemy[Target.NameImages + Target.PosImages.ToString()].Width,
                    Target.XmlEnemy[Target.NameImages + Target.PosImages.ToString()].Height);

                return Target.RecEnemy.Contains(new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, InfoMouseMove.XmlSpriteBatch[InfoMouseMove.NameImages + InfoMouseMove.IndexPosImages.ToString()].Width, InfoMouseMove.XmlSpriteBatch[InfoMouseMove.NameImages + InfoMouseMove.IndexPosImages.ToString()].Height));
            }
            return false;
        }

        public Vector2 GetOrigin()
        {
            return new Vector2(InfoMouseMove.XmlSpriteBatch[InfoMouseMove.NameImages + InfoMouseMove.IndexPosImages.ToString()].Width / 2, InfoMouseMove.XmlSpriteBatch[InfoMouseMove.NameImages + InfoMouseMove.IndexPosImages.ToString()].Height / 2);
        }

        public void DrawMouse(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(InfoMouseMove.SpriteBatch, InfoMouseMove.VecMouse, InfoMouseMove.XmlSpriteBatch[InfoMouseMove.NameImages + InfoMouseMove.IndexPosImages.ToString()], Color.White, 1f, GetOrigin(), 1f, SpriteEffects.None, 1); ;
        }
        #endregion
    }
}
